import Page
from Page import Service
from Base.Base import Base
from selenium.webdriver.common.by import By


class ServiceMaintenanceplanPage(Base):
    """
    养车计划
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.maintenance_home_btn = (By.XPATH, Service.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.maintenance_back_btn = (By.XPATH, Service.RESOURCE_ID.format('ivBack'))

        # 保养节点图标
        self.maintenance_node_icon = (By.XPATH, Service.car_play_node_icon.format(""))

        # 保养节点进度图标
        self.maintenance_schedule_icon = (By.XPATH, Service.car_play_schedule_icon.format(""))

        # 第几次保养
        self.maintenance_times_text = (By.XPATH, Service.car_play_times_text.format(""))

        # 建议保养里程标题
        self.maintenance_mileage_title_text = (By.XPATH, Service.car_play_mileage_title_text.format(""))

        # 建议保养里程公里数
        self.maintenance_mileage_number_text = (By.XPATH, Service.car_play_mileage_number_text.format(""))

        # 建议保养时间
        self.maintenance_mileage_time_text = (By.XPATH, Service.car_play_mileage_time_text.format(""))

        # 建议保养项目
        self.maintenance_mileage_project_title_text = (By.XPATH, Service.car_play_mileage_project_title_text.format(""))

        # 建议保养项
        self.maintenance_mileage_project_text = (By.XPATH, Service.car_play_mileage_project_text.format(""))

        # 去保养按钮
        self.maintenance_mileage_go_maintenance_btn = (By.XPATH, Service.car_play_mileage_go_maintenance_btn.format(""))

        # 滑动条图标
        self.maintenance_slider_img = (By.XPATH, Service.RESOURCE_ID.format("scroll_bar"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.maintenance_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.maintenance_back_btn)

    def get_node(self, index=1):
        """
        获取保养节点图标

        :return: 获取元素
        """
        self.maintenance_node_icon = (By.XPATH, Service.car_play_node_icon.format(index))
        return self.find_element_o(self.maintenance_node_icon)

    def get_schedule(self, index=1):
        """
        获取保养进度图标

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_schedule_icon = (By.XPATH, Service.car_play_schedule_icon.format(index))
        return self.find_element_o(self.maintenance_schedule_icon)

    def get_times(self, index=1):
        """
        获取保养次数文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_times_text = (By.XPATH, Service.car_play_times_text.format(index))
        return self.find_element_o(self.maintenance_times_text)

    def get_mileage_title(self, index=1):
        """
        获取建议保养里程标题文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_mileage_title_text = (By.XPATH, Service.car_play_mileage_title_text.format(index))
        return self.find_element_o(self.maintenance_mileage_title_text)

    def get_mileage_number(self, index=1):
        """
        获取建议保养里程文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_mileage_number_text = (By.XPATH, Service.car_play_mileage_number_text.format(index))
        return self.find_element_o(self.maintenance_mileage_number_text)

    def get_mileage_time(self, index=1):
        """
        获取建议保养时间文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_mileage_time_text = (By.XPATH, Service.car_play_mileage_time_text.format(index))
        return self.find_element_o(self.maintenance_mileage_time_text)

    def get_mileage_project_title(self, index=1):
        """
        获取建议保养项目标题文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_mileage_project_title_text = (
            By.XPATH, Service.car_play_mileage_project_title_text.format(index))
        return self.find_element_o(self.maintenance_mileage_project_title_text)

    def get_mileage_project(self, index=1):
        """
        获取建议保养项目标题文本

        :param index: 输入次数,默认1, 页面取值范围[1,3]
        :return: 获取元素
        """
        self.maintenance_mileage_project_text = (By.XPATH, Service.car_play_mileage_project_text.format(index))
        return self.find_element_o(self.maintenance_mileage_project_text)

    def click_mileage_go_maintenance(self, index=1):
        """
        获取建议保养项目标题文本

        :param index: 默认去保养
        :return: 获取元素
        """
        self.maintenance_mileage_go_maintenance_btn = (
            By.XPATH, Service.car_play_mileage_go_maintenance_btn.format(index))
        self.click_element(self.maintenance_mileage_go_maintenance_btn)

    def get_slider(self):
        """
        获取滑动条图标

        :return: 获取元素
        """
        return self.find_element_o(self.maintenance_slider_img)

    def is_display_service_maintenance(self):
        """
        是否进入维保首页界面

        :return: bool
        """
        return self.is_display(self.maintenance_times_text)
